package graph;


import java.util.*;

public class Node {
    public int val;
    public List<Node> neighbors;

    public Node() {
        val = 0;
        neighbors = new ArrayList<Node>();
    }

    public Node(int _val) {
        val = _val;
        neighbors = new ArrayList<Node>();
    }

    public Node(int _val, ArrayList<Node> _neighbors) {
        val = _val;
        neighbors = _neighbors;
    }

    public static Node init(int[][] edges){
        Map<Integer,Node> map = new HashMap<>();
        for (int i = 0; i <edges.length ; i++) {
            Node node = map.getOrDefault(i+1,new Node(i+1));
            for (int j = 0; j < edges[i].length; j++) {
                Node neighbor = map.getOrDefault(edges[i][j],new Node(edges[i][j]));
                node.neighbors.add(neighbor);
                map.put(edges[i][j],neighbor);
            }
            map.put(i+1,node);
        }
        return map.get(1);
    }
}
